package com.gxa.service.impl;

import com.gxa.common.JsonResult;
import com.gxa.common.PageRecv;
import com.gxa.common.R;
import com.gxa.mapper.WorkReportMapper;
import com.gxa.pojo.Employee;
import com.gxa.pojo.Workreport;
import com.gxa.service.WorkReportSercvice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WorkReportSercviceImpl implements WorkReportSercvice {
    @Autowired(required = false)
    private WorkReportMapper workReportMapper;


    @Override
    public JsonResult queryWorkRep(Integer currentPage,Integer pageSize) {
        JsonResult jsonResult=new JsonResult();
        Integer param1=(currentPage-1)*pageSize;
        Integer param2=pageSize*currentPage;
        List<Workreport> workreportList=workReportMapper.queryWorkRep(param1,param2);
        int count =workReportMapper.countqueryWorkRep() ;
        jsonResult.setCode(200);
        jsonResult.setMsg("查询成功！");
        jsonResult.setData(workreportList);
        jsonResult.setCount(count);
        return jsonResult;
    }

    @Override
    public R commentWorkRep(Workreport workreport) {
        R r=new R();
        workReportMapper.commentWorkRep(workreport);
        r.setCode(200);
        r.setMsg("批注成功！");
        return r;
    }

    @Override
    public R deleteWorkRep(Integer id) {
        R r=new R();
        workReportMapper.deleteWorkRep(id);
        r.setCode(200);
        r.setMsg("删除成功！");
        return r;
    }

    @Override
    public R addWorkRep(Workreport workreport) {
        R r=new R();
        workReportMapper.addWorkRep(workreport);
        r.setCode(200);
        r.setMsg("添加成功！");
        return r;

    }

    @Override
    public  JsonResult queryEmpByDeptId(Employee employee) {
        JsonResult r=new JsonResult();
        List<Employee> employeeList=workReportMapper.queryEmpByDeptId(employee);
        r.setCode(200);
        r.setMsg("查询成功！");
        r.setData(employeeList);
        return r;
    }

    @Override
    public JsonResult searchquery(PageRecv<Workreport> pageRecv) {
        //对查询页面参数计算
        Integer currentPage=pageRecv.getCurrentPage();
        Integer pageSize=pageRecv.getPageSize();
        Integer limit1=(currentPage-1)*pageSize;
        pageRecv.setCurrentPage(limit1);
        //获取查询条件实体
        Workreport workreport = pageRecv.getData();
//      System.out.println(repository);
        //调用mapper方法，返回查询结果list
//        System.out.println("---进入service层---");
        List<Workreport> list=workReportMapper.selectWorkR(pageRecv);
        Integer count=workReportMapper.countselectWorkR(pageRecv);
        //将list和count条数塞入r,响应成功返回
        JsonResult r=new JsonResult();
        r.setCode(200);
        r.setCount(count);
        r.setMsg("搜索成功");
        r.setData(list);
        return r;
    }
}
